package extreme.fizzbuzz.first;

import extreme.fizzbuzz.common.Constants;

import java.util.Scanner;

/**
 * ClassName: FirstHomeWork.
 * Description:
 * Date: 2022/2/11 18:10
 *
 * @author YangXin
 */
public class FirstHomeWork {

    public static void main(String[] args) {
        while (true) {
            Scanner scanner = new Scanner(System.in);
            System.out.print("输入序号：");
            int n = scanner.nextInt();
            System.out.println(numberOff(n));
        }
    }

    public static String numberOff(int number) {
        String numberStr = String.valueOf(number);
        if (numberStr.contains(String.valueOf(7))) {
            if (numberStr.contains(String.valueOf(5))) {
                if (number % 3 == 0) {
                    return Constants.FIZZ;
                } else {
                    return String.valueOf(number);
                }
            } else {
                return basic37Rule(number);
            }
        } else if (numberStr.contains(String.valueOf(5))) {
            return basic57Rule(number);
        } else if (numberStr.contains(String.valueOf(3))) {
            return Constants.FIZZ;
        } else {
            return basicRule(number);
        }
    }

    private static String basic37Rule(int number) {
        String result = "";
        if (number % 3 == 0) {
            result += Constants.FIZZ;
        }
        if (number % 7 == 0) {
            result += Constants.WHIZZ;
        }
        if ("".equals(result)) {
            result = String.valueOf(number);
        }
        return result;
    }


    private static String basic57Rule(int number) {
        String result = "";
        if (number % 5 == 0) {
            result += Constants.BUZZ;
        }
        if (number % 7 == 0) {
            result += Constants.FIZZ;
        }
        if ("".equals(result)) {
            result = String.valueOf(number);
        }
        return result;
    }

    private static String basicRule(int number) {
        String temp = "";
        if (number % 3 == 0) {
            temp += Constants.FIZZ;
        }
        if (number % 5 == 0) {
            temp += Constants.BUZZ;
        }
        if (number % 7 == 0) {
            temp += Constants.WHIZZ;
        }
        if ("".equals(temp)) {
            temp = String.valueOf(number);
        }
        return temp;
    }
}
